
<template>
  <section class="carTypeConfig">
    <el-dialog
      v-dialogDrag
      title="信息来源"
      :visible.sync="curPopupsVisible"
      width="1000px"
      center
      @close="closeCode"
      :close-on-click-modal="false"
      :append-to-body="true"
    >
      <dialogHeader slot="title" :title="'信息来源'" :styleType="$store.state.app.dialogType"></dialogHeader>
      <one-table-template
        ref="multipleTable"
        :dynamicButtons="tableButtons"
        :dynamicComponents="tableComponents"
        :dynamicApiConfig="apiConfig"
        :dynamicTableCols="tableCols"
        :dynamicFormFields="formField"
        :dynamicIsShowSelect="isMul"
        :dynamicIsInitTable="false"
        :isShowPagination="false"
        :callbackObj="callbackObj"
      />
    </el-dialog>
  </section>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import { valueObjectMixins } from "@/components/mixins/valueObjectMixins";
import { crmApis } from "@/api/apiList/crm";
import OneTableTemplate from "@/components/crm/commonComponents/crmPopupsOneTable";
export default {
  // 组件混入对象：{data[listQuery] methods[queryTable]}
  mixins: [oneTableWithViewTemplateMixins, valueObjectMixins],
  components: {
    OneTableTemplate,
    dialogHeader: () => import("@/components/dialogHeader") //弹窗标题
  },
  data() {
    return {
      callbackObj: {
        // 查询成功后回调
        onQueryReturn: response => {
          this.onQueryReturn(response);
        }
      },
      // 网格查询API配置对象
      apiConfig: crmApis.sourceChannelInfoQueryChoose,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.queryTable(1),
          text: "查询",
          position: "top"
        },
        {
          compKey: "btnKey2",
          type: "primary",
          size: "small",
          clickEvent: () => this.sendCode(this.codeField, "infoChanDName"),
          // clickEvent: () => this.sendCode(),
          text: "确认",
          position: "bottom"
        },
        {
          compKey: "btnKey3",
          type: "",
          size: "small",
          clickEvent: () => this.reset1(),
          text: "重置",
          position: "top"
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        // 显示组件

        {
          compKey: "compKey1",
          labelName: "线索渠道",
          codeField: "cantactWayId",
          textField: "cantactWayName",
          lookuptype: crmApis.pcDbCantactWayQueryFindAll,
          component: () =>
            import("@/components/crm/lookupValue/singleDropList"),
          type: "dropdownList",
          isMust: true,
          isMul: false,
          disabled: true,
          getDropValue: this.getMidClass,
        },
        {
          compKey: "compKey2",
          labelName: "一级信息来源",
          codeField: "infoChanMId",
          textField: "infoChanMName",
          isRequire: false,
          isMust: false,
          isMul: false,
          lookuptype: crmApis.pcDbInfoChanMQueryFindAll,
          changeCodeArray: [{ changCode: "cantactWayId" }],
          component: () => import("@/components/crm/lookupValue/secondDropList")
        },
        {
          compKey: "compKey3",
          labelName: "二级信息来源",
          codeField: "infoChanDName",
          component: () => import("@/components/crm/textbox/crmTextInput"),
          type: "inputText",
          isMust: true
        }
      ],
      // 动态生成网格列
      tableCols: [
        {
          prop: "cantactWayName",
          label: "线索渠道",
          width: null,
          align: "center"
        },
        {
          prop: "infoChanMName",
          label: "一级信息来源",
          width: null,
          align: "center"
        },
        {
          prop: "infoChanDName",
          label: "二级信息来源",
          width: null,
          align: "center"
        },
        {
          prop: "cantactWayCode",
          label: "",
          width: null,
          align: "center",
          hidden: true
        },
        {
          prop: "infoChanMCode",
          label: "",
          width: null,
          align: "center",
          hidden: true
        },
        {
          prop: "infoChanDCode",
          label: "",
          width: null,
          align: "center",
          hidden: true
        },
        {
          prop: "cantactWayId",
          label: "",
          width: null,
          align: "center",
          hidden: true
        },
        {
          prop: "infoChanMId",
          label: "",
          width: null,
          align: "center",
          hidden: true
        },
        {
          prop: "infoChanDId",
          label: "",
          width: null,
          align: "center",
          hidden: true
        }
      ],
      //表单查询数据（查询条件）
      formField: {
        cantactWayId: "CS002",
        infoChanMId: "",
        infoChanDName: ""
        // isEnable: "1",
      },
            //双击事件
      handleTableRowData:{
        value:this.codeField,
        text:"infoChanDName"
      }
    };
  },

  mounted(){
    this.$nextTick(function() {
      // this.formField.infoChanMId=this.$parent.infoChanMCode;
      this.$refs.multipleTable.queryTable('-1','','-1')
      if(this.$parent.infoChanMCode&&this.formField.cantactWayId=='CS001'){
        this.tableComponents[1].disabled=true
      }else{
        this.tableComponents[1].disabled=false
      }
    });
  },

  methods: {
    getMidClass(val, txt, comName) {
      let that = this;
      that.$refs.multipleTable.$refs.compKey2[0].getData(val, txt, comName);
    },
    onQueryReturn(){
      this.$refs.multipleTable.$refs.compKey2[0].getData(this.formField.cantactWayId);
    },
    //
    reset1(){
      this.reset();
      if(!this.tableComponents[1].disabled){
        this.formField.infoChanMId=''
      }
    },

  }
};
</script>
